﻿@using Gardener.Base
@using Gardener.CodeGeneration.Resources;
@using Gardener.SystemManager.Dtos
@inherits EditOperationDialogBase<CodeGenDto, Guid, CodeGenLocalResource>

<Form Loading="@_dialogLoading.Value"
      Model="@_editModel"
      LabelCol="new ColLayoutParam { Span = 8 }"
      WrapperCol="new ColLayoutParam { Span = 16 }"
      OnFinish="OnFormFinish"
      Context="model">
    <Row Gutter="24">
        <GridCol Span="12">
            <FormItem Label="@(Localizer[CodeGenLocalResource.TableName])">
                <Select DataSource="_allTables"
                        Style="width:300px;"
                        OnSelectedItemChanged="OnTableSelectChanged"
                @bind-Value="@model.TableName"
                        ValueName="@nameof(SelectItem.ValueName)"
                        LabelName="@nameof(SelectItem.LabelName)"
                        TItem="SelectItem"
                        TItemValue="string"
                        EnableSearch
                        AllowClear>
                </Select>
            </FormItem>

            <FormItem Label="@(Localizer[CodeGenLocalResource.ClassName])">
                <Input @bind-Value="@model.ClassName" Placeholder=@Localizer[CodeGenLocalResource.ClassName] />
            </FormItem>

            <FormItem Label="@(Localizer[CodeGenLocalResource.Module])">
                <Input @bind-Value="@model.Module" Placeholder=@Localizer[CodeGenLocalResource.Module] />
            </FormItem>

            <FormItem Label="@(Localizer[CodeGenLocalResource.Remark])">
                <Input @bind-Value="@model.Remark" />
            </FormItem>



            <FormItem Label="@(Localizer[CodeGenLocalResource.ParentMenu])">
                <Input @bind-Value="@model.MenuParentId" Type="hidden" />
                @if (_menuTree != null && _menuTree.Count > 0)
                {
                    <TreeSelect TItem="ResourceDto"
                                Style="width:100%;"
                                DataSource="_menuTree"
                    @bind-Value="@_menuParentId"
                                Placeholder="@Localizer[CodeGenLocalResource.PleaseSelect]"
                                AllowClear="false"
                                TitleExpression="node=>Localizer[node.DataItem.Name]"
                                KeyExpression="node =>node.DataItem.Id.ToString()"
                                ChildrenExpression="node =>node.DataItem.Children?.ToList()"
                                IsLeafExpression="node =>node.DataItem.Children==null || !node.DataItem.Children.Any()"
                                TreeDefaultExpandAll="true"
                                ShowExpand="true"
                                DisabledExpression="node=>node.DataItem.Id.Equals(_editModel.Id)">
                    </TreeSelect>
                }
            </FormItem>

            <FormItem Label="@(Localizer[CodeGenLocalResource.IconName])">
                <Input @bind-Value="@model.IconName" Placeholder=@Localizer[CodeGenLocalResource.IconName] />
            </FormItem>



            <FormItem Label="@(Localizer[CodeGenLocalResource.PrimaryKeyName])">
                <Input @bind-Value="@model.PrimaryKeyName" Placeholder=@Localizer[CodeGenLocalResource.PrimaryKeyName] />
            </FormItem>

            <FormItem Label="@(Localizer.Combination(CodeGenLocalResource.TableDescription,"(",CodeGenLocalResource.EN,")"))">
                <Input @bind-Value="@model.TableDescriptionEN" />
            </FormItem>

            <FormItem Label="@(Localizer.Combination(CodeGenLocalResource.TableDescription,"(",CodeGenLocalResource.CH,")"))">
                <Input @bind-Value="@model.TableDescriptionCH" />
            </FormItem>
            <FormItem Label="@(Localizer.Combination(CodeGenLocalResource.MenuName,"(",CodeGenLocalResource.EN,")"))">
                <Input @bind-Value="@model.MenuNameEN" Placeholder=@(Localizer.Combination(CodeGenLocalResource.MenuName,"(",CodeGenLocalResource.EN,")")) />
            </FormItem>

            <FormItem Label="@(Localizer.Combination(CodeGenLocalResource.MenuName,"(",CodeGenLocalResource.CH,")"))">
                <Input @bind-Value="@model.MenuNameCH" Placeholder=@(Localizer.Combination(CodeGenLocalResource.MenuName,"(",CodeGenLocalResource.CH,")")) />
            </FormItem>
        </GridCol>
        <GridCol Offset="1" Span="11">

            <FormItem Label="@Localizer[CodeGenLocalResource.Generate]">
                <CheckboxGroup Style="width:100%">
                    <Row>
                        <Col Span="8">
                        <Checkbox @bind-Value="@model.GenerateProjectFile">
                                @(Localizer[CodeGenLocalResource.GenerateProjectFile])
                        </Checkbox>
                        </Col>
                        <Col Span="8">
                        <Checkbox @bind-Value="@model.GenerateBaseClass">
                                @(Localizer[CodeGenLocalResource.GenerateBaseClass])
                        </Checkbox>
                        </Col>
                        <Col Span="8">
                        <Checkbox @bind-Value="@model.GenerateService">
                                @(Localizer["GenerateService"])
                        </Checkbox>
                        </Col>
                        <Col Span="8">
                        <Checkbox @bind-Value="@model.GenerateLocaleFile">
                                @(Localizer["GenerateLocaleFile"])
                        </Checkbox>
                        </Col>
                    </Row>
                </CheckboxGroup>
            </FormItem>
            <FormItem Label="@Localizer[CodeGenLocalResource.Button]">
                <CheckboxGroup Style="width:100%">
                    <Row>
                        <Col Span="8">
                        <Checkbox @bind-Value="@model.HasAdd">
                                @(Localizer[CodeGenLocalResource.HasAdd])
                        </Checkbox>
                        </Col>
                        <Col Span="8">
                        <Checkbox @bind-Value="@model.HasEdit">
                                @(Localizer[CodeGenLocalResource.HasEdit])
                        </Checkbox>
                        </Col>
                        <Col Span="8">
                        <Checkbox @bind-Value="@model.HasDelete">
                                @(Localizer[CodeGenLocalResource.HasDelete])
                        </Checkbox>
                        </Col>
                        <Col Span="8">
                        <Checkbox @bind-Value="@model.HasBatchDelete">
                                @(Localizer[CodeGenLocalResource.HasBatchDelete])
                        </Checkbox>
                        </Col>
                    </Row>
                </CheckboxGroup>
            </FormItem>
            <FormItem Label=@Localizer["GenerateSelectFields"]>
                <Switch @bind-Value="@model.GenerateSelectFields"></Switch>
            </FormItem>
            <FormItem Label=@Localizer[CodeGenLocalResource.UseCustomTemplate]>
                <Switch @bind-Value="@model.UseCustomTemplate"></Switch>
            </FormItem>

            <FormItem Label=@Localizer[CodeGenLocalResource.UseChineseKey]>
                <Switch @bind-Value="@model.UseChineseKey"></Switch>
            </FormItem>
            <FormItem Label=@Localizer["UseNetColumnAsKey"]>
                <Switch @bind-Value="@model.UseNetColumnAsKey"></Switch>
            </FormItem>


            <FormItem Label=@Localizer[CodeGenLocalResource.EntityFromTable]>
                <Tooltip Title="@Localizer[CodeGenLocalResource.ExplainEntityFromTable]" ArrowPointAtCenter="true">
                    <Switch @bind-Value="@model.EntityFromTable"></Switch>
                </Tooltip>
                @if (model.EntityFromTable)
                {
                    <Collapse DefaultActiveKey="@(new[]{"1"})">
                        <Panel Header="@(Localizer[CodeGenLocalResource.EntityFromTableSettings])" Key="1" Active="@model.EntityFromTable">
                            <FormItem Label="@(Localizer[CodeGenLocalResource.OriginalModule])">
                                <Input @bind-Value="@model.OriginModule" Placeholder=@Localizer[CodeGenLocalResource.OriginalModule] />
                            </FormItem>

                            <FormItem Label="@(Localizer[CodeGenLocalResource.NewTableName])">
                                <Input @bind-Value="@model.NewTableName" Placeholder=@Localizer[CodeGenLocalResource.NewTableName] />
                            </FormItem>

                            <FormItem Label=@Localizer[CodeGenLocalResource.AllowNull]>
                                <Tooltip Title="@Localizer[CodeGenLocalResource.ExplainAllowNull]" ArrowPointAtCenter="true">
                                    <Switch @bind-Value="@model.AllowNull"></Switch>
                                </Tooltip>
                            </FormItem>
                        </Panel>
                    </Collapse>
                }
            </FormItem>



            @if (this.Options.Type.Equals(OperationDialogInputType.Edit) || this.Options.Type.Equals(OperationDialogInputType.Select))
            {
                <FormItem Label="@Localizer[CodeGenLocalResource.CreatedTime]">
                    <span>@model.CreatedTime.ToString(ClientConstant.DateTimeFormat)</span>
                </FormItem>
                <FormItem Label="@Localizer[CodeGenLocalResource.UpdatedTime]">
                    <span>@model.UpdatedTime?.ToString(ClientConstant.DateTimeFormat)</span>
                </FormItem>
            }
        </GridCol>
    </Row>
    <Row Gutter="24">
        <GridCol Offset="6" Span="18">
            <FormItem WrapperColOffset="8" WrapperColSpan="16">
                <Space>
                    @if (this.Options.Type == OperationDialogInputType.Edit)
                    {
                        <SpaceItem>
                            <Button Type="@ButtonType.Primary" OnClick="OnlySaveCodeGen">
                                @Localizer[CodeGenLocalResource.OnlySave]
                            </Button>
                        </SpaceItem>
                        <SpaceItem>
                            <Button Type="@ButtonType.Primary" Danger HtmlType="submit">
                                @Localizer[CodeGenLocalResource.SaveAndResetSettings]
                            </Button>
                        </SpaceItem>
                    }
                    else if (this.Options.Type == OperationDialogInputType.Add)
                    {
                        <SpaceItem>
                            <Button Type="@ButtonType.Primary" HtmlType="submit">
                                @Localizer[CodeGenLocalResource.Save]
                            </Button>
                        </SpaceItem>
                    }
                    <SpaceItem>
                        <Button OnClick="_=>OnFormCancel()">
                            @Localizer[CodeGenLocalResource.Cancel]
                        </Button>
                    </SpaceItem>
                </Space>
            </FormItem>
        </GridCol>
    </Row>
</Form>